package com.cloudcc.mobile.view.dynamic;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import butterknife.Bind;

import com.cloudcc.cloudframe.bus.EventList.DynamicEvent;
import com.cloudcc.mobile.R;
import com.cloudcc.mobile.manager.RunTimeManager;
import com.cloudcc.mobile.view.base.BaseFragmentActivity;
import com.cloudcc.mobile.view.dynamic.dynamic.DynamicFragment;
import com.cloudcc.mobile.widget.CloudCCTitleBar;
import com.cloudcc.mobile.widget.CloudCCTitleBar.OnTitleBarClickListener;

public class DynamicOneListActivity extends BaseFragmentActivity implements
		OnTitleBarClickListener {
	private String mEns = RunTimeManager.getInstance().getlanguage();
	@Bind(R.id.headerbar)
	protected CloudCCTitleBar headerbar;

	@Override
	public void init(Bundle savedInstanceState) {
		super.init(savedInstanceState);
		DynamicAboutOneFragment dynamicAboutOneFragment = new DynamicAboutOneFragment();
		dynamicAboutOneFragment.setArguments(getIntent().getExtras());
		getSupportFragmentManager().beginTransaction()
				.add(getContainerId(), dynamicAboutOneFragment).commit();
		headerbar.setOnTitleBarClickListener(this);
	}
	private class DynamicAboutOneFragment extends DynamicFragment {

		private String userName;
		private String userId;

		@Override
		public void init() {
			Bundle bundle = getArguments();
			if ("en".equals(mEns)) {
				if (bundle != null) {
					userName = bundle.getString("userName", "Colleague");
					userId = bundle.getString("userId");
					if (userId == null) {// 关闭
						Toast.makeText(mContext, "Sorry to get colleague information failed...", 0).show();
						getActivity().finish();
					}
				}

				headerbar.setTitle(userName + "The cloud posts");
			}else{
				if (bundle != null) {
					userName = bundle.getString("userName", "同事");
					userId = bundle.getString("userId");
					if (userId == null) {// 关闭
						Toast.makeText(mContext, "对不起获取同事信息失败...", 0).show();
						getActivity().finish();
					}
				}

				headerbar.setTitle(userName + "的云帖");
		}
			

			super.init();
		}

		@Override
		public String getQueryType() {
			return "self";
		}

		@Override
		public void requestData() {
			headerbar.beginProgress();
			mControl.getDynamicForOne(currentPage, userId);
		}

		@Override
		public void onEventMainThread(DynamicEvent event) {
			super.onEventMainThread(event);
			headerbar.completeProgress();
		}

	}

	@Override
	public void onClickLeft(View v) {
		finish();

	}

	@Override
	public void onClickRight(View v) {

	}

	@Override
	public int getLayoutId() {
		return R.layout.dynamic_onelist;
	}

}
